<?php
namespace app\admin\model;

use think\Model;

class Admin extends Base
{
    protected $name = 'admin';

    // 启用||禁用
    public function setStatus($id){
        $info = $this->getFind(['id' => $id])['data'];

        if($info['status'] == 0){
            $status       = 1;
            $back['flag'] = 1;
            $back['msg']  = '启用成功';
        }else{
            $status       = 0;
            $back['flag'] = 0;
            $back['msg']  = '禁用成功';
        }

        $data = [
            'id'      => $id,
            'status'  => $status,
        ];
        
        $this->update($data);
        return $back;
    }

    public function getRoleIDAttr($val){
        if($val == 0){
            return '超级管理员';
        }

        return (new Role())->getVal(['id' => $val], 'name')['data'];
    }
}